// 主页滚动的中奖纪录名单
function marguee() {
	$.ajax({
			url: url + '/Slots/winning_lst',
			type: 'post',
			dataType: 'json'
		})
		.done(function(data) {
//			var data = data.data
			var html = ''
			for (var i = 0; i < data.data.length; i++) {
				html += '<li><span>'+congratulation+'</span>' + data.data[i].username +'<span>'+ get+'</span>' + data.data[i].product_title + '</li>'
			}
			$('#marquee ul').html(html)
			$('#marquee').kxbdMarquee({
				isEqual: false,
				loop: 1,
				newAmount: 0,
				scrollDelay: 60
			});
		})
		.fail(function() {
			console.log("error");
		})
}
marguee()

window.setInterval(function() {
	$('#marquee ul').html('')
	marguee()
}, 60000);







var status 
var rand;
var isBegin = false;
var start = true;
var u = 90
var arr = []

function numRand() {
	var x = 777; //上限
	var y = 111; //下限
	$.ajax({
		url: url + 'Slots_detail/lucky_draw_npoint/',
		type: 'GET',
		async: false,
		success: function(data) {
			var data = JSON.parse(data)
			console.log(data)
			if (data.code == 1) {
				$('#xf_all').attr("data-count",data.data.npoint_count)
				$('#xf_all').html($('#xf_all').html() - 10)
				status = data.data.status
				rand = parseInt(data.data.pointer_location1 * 100 + data.data.pointer_location2 * 10 + data.data.pointer_location3 * 1);
				
				arr.rand = rand
				arr.status = status
				$('.mask_title').html(data.data.desc)
				$('.mask_img img').attr('src', data.data.hint_img)
				$('.consumption').html(data.data.desc)
			} else if (data.code == 2) {
				alert(data.desc)
				$('#xf_all').html(data.data.npoint_count)
				arr=[]
			}
		},
		error: function(xhr, textStatus) {
			if (xhr.status == 401) {
				window.location.href = url + "/Login";
			} else if(xhr.status == 0){
				alert(interneterror)
			}else{
				alert(errordata)
			}
		}
	})
	return arr;
}


// 开始抽奖
$('.btn').click(function() {
	starts()
});
// 再来一次
$('.btn_again').click(function() {
	$('.mask').hide()
	starts()
});
$('.mask_con').click(function(event) {
	$('.mask').hide()
});



function starts(){
	if(isBegin) return false;
	isBegin = true;

	$(".num").css('backgroundPositionY',30);
	var zzz = numRand();
	var result = zzz.rand; //中奖数字
	console.log(result)
	var Status = zzz.status;


	var num_arr = (result+'').split('');
	if (result) {
		$(".num").each(function(index){
			var _num = $(this);
			setTimeout(function(){
				_num.animate({ 
					// backgroundPositionY: (5610)  //滚动个数的整数倍
					backgroundPositionY: (u*84)+30 - (u*num_arr[index]) //滚动个数的整数倍
				},{
					duration: 3000+index*1000,
					// duration: 6000+index*3000,
					easing: "easeInOutCirc",
					complete: function(){
						if(index==2) {
							$('#xf_all').html($('#xf_all').attr("data-count"))
							isBegin = false;
							start = true;
							if (Status == 1) {
								//三个一样的情况下
								
								$('.mask').show()
							}else if(Status ==2){
								// 两个一样的情况
								$('.consumption').addClass('consumption_xf')
								setTimeout(function(){
									$('.consumption').removeClass('consumption_xf')
								},2000)
							}

							
						}
					}
				});
			}, index * 0);
		});
	}else{
		isBegin = false;
		start = true;
	}
	
}